*CCES Data

cd "BYU module data/" // change this if you're working on another computer

use "CCES18_BYU_OUTPUT.DTA", clear

*recode the variables for easier usage
gen attractiveness_score=.
replace attractiveness_score=BYU307 if BYU307<=100

gen respond_message=.
replace respond_message=BYU308_1 if BYU308_1<=6

recode respond_message (6=1) (5=2) (4=3) (3=4) (2=5) (1=6), gen(respond_message_flip)

gen go_date=.
replace go_date=BYU308_2 if BYU308_2<=6

recode go_date (6=1) (5=2) (4=3) (3=4) (2=5) (1=6), gen(go_date_flip)


gen relationship=.
replace relationship=BYU308_3 if BYU308_3<=6

recode relationship (6=1) (5=2) (4=3) (3=4) (2=5) (1=6), gen(relationship_flip)


*Standardize our outcomes
egen attractiveness_score_std=std(attractiveness_score), mean(0) std(1)
egen respond_message_flip_std=std(respond_message_flip), mean(0) std(1) 
egen relationship_flip_std=std(relationship_flip), mean(0) std(1) 
egen go_date_flip_std=std(go_date_flip), mean(0) std(1) 

*BYU306 -> 1=Rep, 2=Dem, 3=Ind (Respondent party)

*BYU305 -> 1=Men, 2=Women (This is preference)


******************************************************************************
******************************************************************************
*Begin here if you use the updated .csv

tab BYU307rand
*Which one is 1, 2, 3?
*1 Republican
*2 Democrat
*3 Control

gen same_party=.
replace same_party=1 if BYU306==1 & BYU307rand==3
replace same_party=1 if BYU306==2 & BYU307rand==1
replace same_party=0 if BYU306==1 & BYU307rand==1
replace same_party=0 if BYU306==2 & BYU307rand==3

svyset [pw=teamweight]

svy: reg attractiveness_score same_party

svy: reg attractiveness_score_std same_party // for the attractiveness meta-analysis
svy: reg respond_message_flip_std same_party
svy: reg go_date_flip_std same_party
svy: reg relationship_flip_std same_party

	gen age=2018-birthyr 

	svy: reg attractiveness_score_std same_party if age<=35

	
	

******************************************************************************** Factor Weighted Scale


*No set up so we can be consistent about what is going into the scale (CCES doesn't have setup)
factor attractiveness_score respond_message_flip_std go_date_flip_std relationship_flip
predict interact_scale

egen interact_scale_std=std(interact_scale), mean(0) std(1)

regress interact_scale_std same_party	
	
***********************************************************
*************************Coding for Balance Tests *********
***********************************************************

***rename the variables/clean up the dataset
*age
drop age
gen age = .
replace age = (2018 - birthyr )

*gender
gen male = .
replace male = 1 if gender == 1
replace male = 0 if gender == 2

*education (already coded)

*marriage status
gen married=1 if  marstat==1
replace married=0 if married==. & marstat~=.

*race
gen white = 1 if race==1
replace white = 0 if white==.

*sexuality
gen straight = 1 if sexuality==1
replace straight = 0 if straight==. & sexuality~=.

*transgender
rename trans transgender
gen trans = 1 if transgender==1
replace trans=0 if transgender~=1 & transgender~=.

*religiosity
gen religiosity = .
replace religiosity = 1 if pew_churatd  == 6
replace religiosity = 2 if pew_churatd  == 5
replace religiosity = 3 if pew_churatd  == 4
replace religiosity = 4 if pew_churatd  == 3
replace religiosity = 5 if pew_churatd  == 2
replace religiosity = 6 if pew_churatd  == 1

*ideology
rename ideo5 ideology5
gen ideo5 = .
replace ideo5 = 1 if ideology5 == 5
replace ideo5 = 2 if ideology5 == 4
replace ideo5 = 3 if ideology5 == 3
replace ideo5 = 4 if ideology5 == 2
replace ideo5 = 5 if ideology5 == 1

* partyid
gen democrat_respondent=1 if pid3==1
replace democrat_respondent=0 if pid3~=1 & pid3~=.

*political interest
gen poli_interest = .
replace poli_interest = 1 if newsint ==4
replace poli_interest = 2 if newsint == 3
replace poli_interest = 3 if newsint == 2
replace poli_interest = 4 if newsint == 1

*employment
gen employed=1 if employ==1
replace employed=0 if employ~=1 & employ~=.

*income
gen income = .
replace income = 1 if faminc_new  == 1
replace income = 2 if faminc_new  == 2
replace income = 3 if faminc_new  == 3
replace income = 4 if faminc_new  == 4
replace income = 5 if faminc_new  == 5
replace income = 6 if faminc_new  == 6
replace income = 7 if faminc_new  == 7
replace income = 8 if faminc_new  == 8
replace income = 9 if faminc_new  == 9
replace income = 10 if faminc_new  == 10
replace income = 11 if faminc_new  == 11
replace income = 12 if faminc_new  == 12
replace income = 13 if faminc_new  == 13
replace income = 14 if faminc_new  == 14
replace income = 15 if faminc_new  == 15
replace income = 16 if faminc_new  == 16

***********************************************************
*************************Balance Tests ********************
***********************************************************

sum age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income

egen age_std=std(age), mean(0) std(1)

regress age_std same_party
regsave same_party using "balance_experiment_2.dta", detail(all) addlabel(outcome, age, experiment, 2) replace 


foreach var in  male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income {
egen `var'_std=std(`var'), mean(0) std(1)
regress `var'_std same_party
regsave same_party using "balance_experiment_2.dta", detail(all) addlabel(outcome, `var', experiment, 2) append 
}

foreach var in attractiveness_score respond_message go_date relationship  ///
 age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income {
 
 gen `var'm=1 if `var'==.
 replace `var'm=0 if `var'~=.
 
 }
 
 foreach var in  attractiveness_score respond_message go_date relationship  ///
 age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income {
tab `var'm
}


keep same_party age male educ white democrat_respondent ideo5 employed straight trans religiosity poli_interest income attractiveness_scorem respond_messagem go_datem relationshipm  agem malem educm whitem democrat_respondentm ideo5m employedm straightm transm religiositym poli_interestm incomem attractiveness_score respond_message go_date relationship married
gen experiment=2
save "pared_balance_experiment_2.dta", replace



use "balance_experiment_2.dta", clear

gen t=coef/stderr

saveold "balance_experiment_2.dta", version(12) replace
	
	
	
	
	
	
